package com.neusoft.bizcore.activiti.converter;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.neusoft.bizcore.activiti.dto.DataModelDTO;
import com.neusoft.bizcore.activiti.dto.ServiceDataModelDTO;
import com.neusoft.bizcore.activiti.enums.OperationTypeEnum;

public interface IServiceDataConverter<T> {

    default List<ServiceDataModelDTO> defaultConverter(final List<T> list, final String serviceName,
            final OperationTypeEnum type) {
        final List<ServiceDataModelDTO> newList = new ArrayList<>();

        list.stream().forEach(e -> {
            final ServiceDataModelDTO sdm = new ServiceDataModelDTO();
            final DataModelDTO dm = new DataModelDTO();
            sdm.setServiceName(serviceName);

            dm.setJsonData(JSON.toJSONString(e));
            dm.setType(type);

            sdm.setData(dm);
            newList.add(sdm);
        });

        return newList;
    }

}
